import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/themes/cvue/layout/index'

Vue.use(Router)
// 路由实例
const router = new Router({
  scrollBehavior (to, from, savedPosition) { // 路由滚动行为
    if (savedPosition) {
      return savedPosition
    } else {
      const position = {}
      if (to.hash) {
        position.selector = to.hash
      }
      if (to.matched.some(m => m.meta.scrollToTop)) {
        position.x = 0
        position.y = 0
      }
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(position)
        }, 500)
      })
    }
  },
  routes: [
    {
      path: '/home',
      name: 'Home',
      component: () => import(/* webpackChunkName: "Home" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'index',
          name: '首页',
          component: () => import(/* webpackChunkName: "Home" */'../themes/cvue/views/home/index')
        }
      ]
    },
    {
      path: '/shop',
      name: 'shop',
      component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'shop',
          name: '店铺管理',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/shop/index.vue')
        },
        {
          path: 'banner',
          name: 'Banner管理',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/shop/banner.vue')
        },
        {
          path: 'category',
          name: '分类管理',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/shop/category.vue')
        },
        {
          path: 'product',
          name: '产品管理',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/shop/product.vue')
        },
        {
          path: 'order',
          name: '订单管理',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/shop/order.vue')
        }
      ]
    },
    {
      path: '/blog',
      name: 'blog',
      component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'category',
          name: '博客分类',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/blog/category.vue')
        },
        {
          path: 'comment',
          name: '评论管理',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/blog/comment.vue')
        },
        {
          path: 'article',
          name: '文章管理',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/blog/article.vue')
        },
        {
          path: 'siteCategory',
          name: '书签分类',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/blog/siteCategory.vue')
        },
        {
          path: 'site',
          name: '书签管理',
          component: () => import(/* webpackChunkName: "authCenter" */'../themes/cvue/views/blog/site.vue')
        }
      ]
    },
    {
      path: '/user',
      name: 'user',
      component: () => import(/* webpackChunkName: "user" */'../themes/cvue/layout/index'),
      children: [
        {
          path: 'user',
          name: '用户管理',
          component: () => import(/* webpackChunkName: "user" */'../themes/cvue/views/user/index.vue')
        },
        {
          path: 'role',
          name: '角色管理',
          component: () => import(/* webpackChunkName: "user" */'../themes/cvue/views/user/role.vue')
        },
        {
          path: 'menu',
          name: '菜单管理',
          component: () => import(/* webpackChunkName: "user" */'../themes/cvue/views/user/menu.vue')
        },
        {
          path: 'permissions',
          name: '权限管理',
          component: () => import(/* webpackChunkName: "user" */'../themes/cvue/views/user/permissions.vue')
        },
        {
          path: 'log',
          name: '日志管理',
          component: () => import(/* webpackChunkName: "user" */'../themes/cvue/views/user/log.vue')
        },
        {
          path: 'dict',
          name: '字典管理',
          component: () => import(/* webpackChunkName: "user" */'../themes/cvue/views/user/dict.vue')
        }
      ]
    },
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import(/* webpackChunkName: "public" */'../themes/login/login')
    },
    {
      path: '*',
      redirect: '/error/404'
    },
    {
      path: '/error/403',
      name: 'Error403',
      component: () => import(/* webpackChunkName: "public" */'../themes/error/403')
    },
    {
      path: '/error/404',
      name: 'Error404',
      component: () => import(/* webpackChunkName: "public" */'../themes/error/404')
    }
  ]
})
export default router
